package com.amtf.datafile3;

import java.io.File;
import java.net.URI;

public abstract class DataFile extends File {
	private static final long serialVersionUID = 7203988118567253428L;
	protected DataTableDefinition definition = null;
	protected DataAccessor dataAccessor = null;

	public DataFile(DataTableDefinition definition, String pathname) {
		super(pathname);
		this.definition = definition;
	}

	public DataFile(DataTableDefinition definition, URI uri) {
		super(uri);
		this.definition = definition;
	}

	public DataFile(DataTableDefinition definition, File file) {
		super(file.getAbsolutePath());
		this.definition = definition;
	}

	public DataTableDefinition getDefinition() {
		return definition;
	}

	public DataCatalog openCatalog() throws DataException {
		DataCatalog dc = dataAccessor.open(this.getPath());
		if (definition != null) {
			dc.setDataTableDefinition(definition);
		}
		return dc;
	}

	public void closeCatalog() throws DataException {
		dataAccessor.commit();
		dataAccessor.close();
	}
}
